知识点名称:反向地理编码

编号: K11-2

前驱知识点编号:K11-1

作者:

讲义内容:

11.2.1 反向地理编码概念

“地理编码”这一术语通常指将易于理解的地址转换成地图上的一个点的过程。与此相反,将地图上的位置转换成易于理解的地址这一过程则称为“反向地理编码”。

地理编码:把普通用户能够看懂的字符串地址转换成为精度,纬度.

反向地理编码:把精度,纬度转换成普通的字符串地址.

11.2.2 GeoCoder类用法

Google Maps Geocoding API 是一项提供地址地理编码和反向地理编码的服务。

可以通过 HTTP 接口访问 Google Maps Geocoding API。此服务通常用于对(预先知道的)静态地址进行地理编码,以便将应用内容放置到地图上

Google Maps Geocoding API 请求格式

Google Maps Geocoding API 请求使用以下格式:

https://maps.googleapis.com/maps/api/geocode/outputFormat?parameters

其中 outputFormat 可以是以下值之一:

  • json(推荐),表示以 JavaScript 对象标记 (JSON) 格式输出;或
  • xml,表示以 XML 格式输出

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=YOUR_API_KEY

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "1600",
               "short_name" : "1600",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Amphitheatre Pkwy",
               "short_name" : "Amphitheatre Pkwy",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Mountain View",
               "short_name" : "Mountain View",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Santa Clara County",
               "short_name" : "Santa Clara County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "California",
               "short_name" : "CA",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "94043",
               "short_name" : "94043",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
         "geometry" : {
            "location" : {
               "lat" : 37.4224764,
               "lng" : -122.0842499
            },
            "location_type" : "ROOFTOP",
            "viewport" : {
               "northeast" : {
                  "lat" : 37.4238253802915,
                  "lng" : -122.0829009197085
               },
               "southwest" : {
                  "lat" : 37.4211274197085,
                  "lng" : -122.0855988802915
               }
            }
         },
         "place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
         "types" : [ "street_address" ]
      }
   ],
   "status" : "OK"
}

results matching ""

    No results matching ""